<template>
  <div>
    <transition name="slide-fade" :duration="5000">
      <div class="valert-wrap" v-if="open">
        <div class="valert" >
          <p>{{ msg }}</p>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'alert',
  data() {
    return {
      msg: '',
      show: false,
      timer: null,
      duration: 2,
    };
  },
  computed: {
    open() {
      this.end();
      return this.show;
    },
  },
  methods: {
    end() {
      if (!this.timer) {
        this.hide();
        this.timer = setTimeout(() => {
          this.comDestory();
        }, this.duration * 1500);
      }
    },
    comDestory() {
      this.$destroy();
      document.body.removeChild(this.$el);
    },
    hide() {
      setTimeout(() => {
        this.show = false;
      }, this.duration * 1000);
    },
  },
};
</script>
<style lang="less">
@import url(../../../static/style/site.vars.less);
  .valert-wrap{
    width: 100%;
    position: fixed;
    height: 0;
    top: 20px;
    text-align: center;
    z-index: 11111;
    .valert{
      display: inline-block;
      width: 330px;
      padding: 10px 15px;
      box-sizing: border-box;
      border: 1px solid #ebeef5;
      background: #fff;
      z-index: 11112;
      margin-top: 0px;
      p {
        font-size: 14px;
        line-height: 21px;
        color: #000000;
        text-align: left;
        margin: 10px 0 ;
      }
    }
  }

  .slide-fade-enter-active {
    transition: all .3s ease;
  }
  .slide-fade-leave-active {
    transition: all .3s cubic-bezier(1.0, 0.5, 0.8, 1.0);
  }
  .slide-fade-enter, .slide-fade-leave-to
  /* .slide-fade-leave-active for below version 2.1.8 */ {
    transform: translateY(-10px);
    opacity: 0;
  }
</style>
